<?php

ini_set('display_errors', 1);
error_reporting(-1);
require_once '/data/wwwroot/g_vendor/autoload.php';

//首件和续件价格都为0的模板设置为包邮类型
use Biz\model\ShippingTempl as mShippingTempl;
use Biz\model\ShippingTemplAttr as mShippingTemplAttr;

use Biz\service\ShippingTempl as sShippingTempl;

//$rs=sShippingTempl::getShippingFee(1582647,[9=>['buy_num'=>11,'weight'=>30]],340000);
//var_dump($rs);die;


$ret=mShippingTemplAttr::update(['type'=>mShippingTemplAttr::TYPE_FREE],['type'=>mShippingTemplAttr::TYPE_NOFREE,'base_price'=>floatval(0),'continued_price'=>0]);
var_dump($ret->errorCode());die;

//去掉多余的包邮未设置区域的非默认数据
$attrRes=mShippingTemplAttr::select('*',['AND'=>['type'=>mShippingTemplAttr::TYPE_FREE,'area'=>'','base_price'=>0,'continued_price'=>0],'ORDER'=>['is_default'=>'DESC']]);
$attrList=[];
foreach($attrRes as $row) {
    $attrList[$row['templ_id']][]=$row;
}
$delAttrIds=[];
$nullTemplIds=[];
foreach($attrList as $templId=>$tempAttrList){
    $isDefault=false;
    foreach($tempAttrList as $row){
        if ($row['is_default']) {
            $isDefault=true;
        }elseif($isDefault){
            array_push($delAttrIds,$row['id']);
            $nullTemplIds[$row['shop_id']][]=$row['templ_id'];
        }
    }
}
var_dump($delAttrIds,$nullTemplIds);die;
$ret=mShippingTemplAttr::update(['status'=>mShippingTemplAttr::STATUS_DELETE],['id'=>$delAttrIds]);
var_dump($ret->errorCode());die;